#include"LPC11xx.h"
#define LED1_ON()   LPC_GPIO2->DATA&=~(1<<0)
#define LED1_OFF()  LPC_GPIO2->DATA|=(1<<0)
#define LED2_ON()  (LPC_GPIO2->DATA &= ~(1<<1)) 	
#define LED2_OFF() (LPC_GPIO2->DATA |= (1<<1)) 		
#define LED3_ON()  (LPC_GPIO2->DATA &= ~(1<<2)) 	
#define LED3_OFF() (LPC_GPIO2->DATA |= (1<<2)) 

void LedInit()
{
	LPC_SYSCON->SYSAHBCLKCTRL|=(1<<16);
	LPC_IOCON->PIO2_0&=~0X07;
	LPC_IOCON->PIO2_0|=0X00;
	LPC_IOCON->PIO2_1&=~0X07;
	LPC_IOCON->PIO2_1|=0X00;
	LPC_IOCON->PIO2_2&=~0X07;
	LPC_IOCON->PIO2_2|=0X00;
	LPC_SYSCON->SYSAHBCLKCTRL&=~(1<<16);
	LPC_SYSCON->SYSAHBCLKCTRL|=(1<<6);
	LPC_GPIO2->DIR|=(1<<0);
	LPC_GPIO2->DATA|=(1<<0);
	LPC_GPIO2->DIR|=(1<<1);
	LPC_GPIO2->DATA|=(1<<1);
	LPC_GPIO2->DIR|=(1<<2);
	LPC_GPIO2->DATA|=(1<<2);
}

void T32B1_Init(void)
{
	LPC_SYSCON->SYSAHBCLKCTRL|=(1<<10);
	LPC_TMR32B1->IR=0X01;
	LPC_TMR32B1->MCR=0X04;
}
void T32B1_DelayMs(uint16_t ms)
{
	LPC_TMR32B1->TCR=0X02;
	LPC_TMR32B1->PR=0;
	LPC_TMR32B1->MR0=ms*(SystemCoreClock/1000);
	LPC_TMR32B1->TCR=0X01;
	while(LPC_TMR32B1->TCR&0X01);
}

int main()
{
	LedInit();
	T32B1_Init();
	while(1)
	{
		T32B1_DelayMs(1000);
		  LED1_ON();
		T32B1_DelayMs(1000);
		  LED1_OFF();
		T32B1_DelayMs(1000);
			LED2_ON();
		T32B1_DelayMs(1000);
		  LED2_OFF();
		T32B1_DelayMs(1000);
		    LED3_ON();
		T32B1_DelayMs(1000);
		    LED3_OFF();
		T32B1_DelayMs(1000);
		   LED1_ON();
		   LED2_ON();
		   LED3_ON();
		T32B1_DelayMs(1000);
			LED1_OFF();
		  LED2_OFF();
		  LED3_OFF();
		
	}
}		
	
	
	
	
	
	
	

